package com.guet.main.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guet.common.utils.R;
import com.guet.main.entity.Admin;
import com.guet.main.entity.vo.AdminVo;
import com.guet.main.service.AdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * admin 前端控制器
 * </p>
 *
 * @author csp
 * @since 2022-07-27
 */
@RestController
@RequestMapping("/main/admin")
@CrossOrigin
public class AdminController {

    private final AdminService adminService;

    public AdminController(AdminService adminService) {
        this.adminService = adminService;
    }

    @ApiOperation("管理员登录")
    @PostMapping("login")
    public R login(@RequestBody AdminVo admin){
        /*QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account",admin.getAccount());
        List<Admin> list = adminService.list(queryWrapper);
        if(!list.isEmpty()){
            if(list.get(0).getPassword().equals(admin.getPassword())){
                return R.ok().data("token","admin");
            }else {
                return R.error();
            }
        }else{
            return R.error();
        }*/
        return R.ok();
    }

    @ApiOperation("获取登录信息")
    @GetMapping("info")
    public R getInfo(){
        return R.ok().data("roles","[admin]").data("name","admin");
    }

    @ApiOperation("退出登录")
    @PostMapping("logout")
    public R logout(){
        return R.ok();
    }

    @ApiOperation("增加管理员")
    @PostMapping("add")
    public R add(@RequestBody Admin admin){
        boolean save = adminService.save(admin);
        return save?R.ok():R.error();
    }


}

